﻿package mortal.game.net.command.buff
{
    import Framework.MQ.*;
    import Message.BroadCast.*;
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.gengine.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.manager.*;
    import mortal.game.manager.mouse.*;
    import mortal.game.mvc.*;
    import mortal.game.net.broadCast.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.cd.*;
    import mortal.game.view.skill.*;
    import mortal.mvc.core.*;

    public class BuffUpdateCommand extends BroadCastCall
    {

        public function BuffUpdateCommand(param1:Object)
        {
            super(param1);
            return;
        }// end function

        override public function call(param1:MessageBlock) : void
        {
            var _loc_4:SBuff = null;
            var _loc_5:SBuffInfo = null;
            super.call(param1);
            var _loc_2:* = param1.messageBase as SBuffUpdate;
            _cache.buff.updateBuff(_loc_2);
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.buffs.length)
            {
                
                _loc_4 = _loc_2.buffs[_loc_3] as SBuff;
                _loc_5 = new SBuffInfo();
                _loc_5.buffId = _loc_4.buffId;
                _loc_5.fromEntityIds = _loc_4.fromEntityIds;
                Cache.instance.role.roleEntityInfo.updateBufferInfo(_loc_5, _loc_2.op);
                this.updateValue(_loc_4.buffId, _loc_2.op);
                _loc_3++;
            }
            NetDispatcher.dispatchCmd(ServerCommand.BufferUpdate, _cache.buff.showBuffArray);
            if (_cache.buff.buffInfoArray.length > 0)
            {
                MouseRuleManager.addRule(Global.stage, MouseThreeClickRule, this.threeClickCall);
            }
            else
            {
                MouseRuleManager.removeRule(Global.stage, MouseThreeClickRule);
            }
            return;
        }// end function

        private function updateValue(param1:int, param2:int) : void
        {
            var _loc_4:int = 0;
            var _loc_6:SkillInfo = null;
            var _loc_7:ICDData = null;
            var _loc_3:* = BuffConfig.instance.getInfoById(param1);
            var _loc_5:* = _loc_3.type;
            if (param2 == EBuffUpdateType._EBuffUpdateTypeRemove)
            {
                _loc_4 = 0;
            }
            else
            {
                _loc_4 = _loc_3.effect;
            }
            Cache.instance.buff.setBuffTypeValue(_loc_3.type, _loc_4);
            switch(_loc_3.type)
            {
                case EBuffType._EBuffTypeIncOrDeSprintCd:
                {
                    _loc_6 = Cache.instance.skill.getSkill(GameConst.JPSkillId);
                    if (_loc_6 != null)
                    {
                        _loc_6.shengeAddCD = _loc_4 * 1000;
                        _loc_7 = Cache.instance.cd.getCDData(_loc_6, CDDataType.skillInfo);
                        if (_loc_7 != null)
                        {
                            _loc_7.totalTime = _loc_6.cooldownTime;
                        }
                    }
                    break;
                }
                case EBuffType._EBuffTypeIncOrDeJumpDist:
                {
                    GameConst._addSomersaultDistance = _loc_4;
                    break;
                }
                case EBuffType._EBuffTypeIncOrDeJumpCd:
                {
                    _loc_6 = Cache.instance.skill.getSkill(GameConst.RollingSkillId);
                    if (_loc_6 != null)
                    {
                        _loc_6.shengeAddCD = _loc_4 * 1000;
                        _loc_7 = Cache.instance.cd.getCDData(_loc_6, CDDataType.skillInfo);
                        if (_loc_7 != null)
                        {
                            _loc_7.totalTime = _loc_6.cooldownTime;
                        }
                    }
                    break;
                }
                default:
                {
                    break;
                }
            }
            NetDispatcher.dispatchCmd("buff_" + _loc_5, _loc_3.type);
            return;
        }// end function

        private function threeClickCall() : void
        {
            if (Cache.instance.buff.isHasRemoveSefTypeBuff)
            {
                GameProxy.sceneProxy.dispelBuffSelf();
            }
            return;
        }// end function

    }
}
